import { http } from "../utils/http";
import { ReturnDTO } from "./type";

const prefix = "/user/role";

export interface RoleInsertDTO {
  roleName: string;
}

export interface RoleUpdateDTO extends RoleInsertDTO {
  id: number;
  key: string;
}

// 获取角色列表
export const getRoleList = (): Promise<ReturnDTO> => {
  return http.request<ReturnDTO>("get", prefix);
};

// 添加
export const addRole = (data: RoleInsertDTO): Promise<ReturnDTO> => {
  return http.request<ReturnDTO>("post", prefix, data as Object);
};

// 更新
export const updateRole = (data: RoleUpdateDTO): Promise<ReturnDTO> => {
  return http.request("put", prefix, data as Object);
};

// 根据id查询
export const getRoleById = (id: number): Promise<ReturnDTO> => {
  return http.request("get", prefix + "/" + id);
};

// 删除
export const deleteRole = (id: number): Promise<ReturnDTO> => {
  return http.request("delete", prefix + "/" + id);
};
